/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* E.P. Scene Graph Viewer
* Developed by:
*       - Eduardo Ribeiro (eribeiro @ tecgraf . puc-rio . br)
*       - Peter Dam (peter @ tecgraf . puc-rio . br)
* File: Mesh.h
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#ifndef _EPSG_MESH_
#define _EPSG_MESH_

#include "EPSG/Vec2.h"
#include "EPSG/Vec3.h"
#include "EPSG/Shape.h"
#include "EPSG/Prototypes.h"

namespace EPSG
{
	typedef struct BoundingBoxStruct
	{
		float xmin, xmax, ymin, ymax, zmin, zmax;
	} BoundingBox;

	typedef struct VertexStruct
	{
		Vec3<float> pos;
		Vec3<float> normal;
	} Vertex;

	typedef struct TexCoordStruct
	{
		Vec3<float> texCoord;
	} TexCoord;

	typedef struct TriangleStruct
	{
		int id;
		Vertex* v1;
		Vertex* v2;
		Vertex* v3;
		Vec3<float> normal;
	} Triangle;

	class Mesh : public Shape
	{
	public:
		/* [CONSTRUCTOR] */	Mesh();
		/* [CONSTRUCTOR] */	Mesh( const char* filename );

		void				loadGeometry( const char* filename );
		void				setSmooth( bool smooth );
		void				getBBox( float* xmin, float* xmax,
									 float* ymin, float* ymax,
									 float* zmin, float* zmax );
		void				draw( bool autoTexCoord = true );

	private:
		Vec3<float>			calcNormal( Triangle* t );
		void				calcTexCoord( Vertex* v, TexCoord* t, Vec3<float> vCenter );
		void				loadMS1( const char* filename );
		void				loadMSH( const char* filename );
		void				loadOBJ( const char* filename );

		bool				_smooth;
		bool				_weighted;

		int					_nVertices;
		Vertex*				_vertices;
		Vertex*				_vertexArray;

		int					_nTexCoords;
		TexCoord*			_texCoords;

		int					_nTriangles;
		Triangle*			_triangles;

		BoundingBox			_bBox;
	};
}

#endif